//
//  SelectSexView.m
//  Doctor
//
//  Created by 阳光 on 16/10/17.
//  Copyright © 2016年 阳光. All rights reserved.
//  性别选择界面

#import "SelectSexView.h"

static NSString *tableViewCellIdentifier=@"UITableViewCellIdentifier";

@interface SelectSexView ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *sexTableView;

@property(nonatomic,strong)NSArray *sexArr;

@end

@implementation SelectSexView

-(instancetype)initWithFrame:(CGRect)frame
{
    self=[super initWithFrame:frame];
    if (self) {
        self.backgroundColor=[[UIColor blackColor] colorWithAlphaComponent:0.5];
        
        // 男 女
        _sexArr=@[NSLocalizedString(@"Male", nil),NSLocalizedString(@"Female", nil)];
 
        [self setView];
        
    }
    return self;
}

-(void)setView
{
    UIView *contentView=[[UIView alloc] initWithFrame:CGRectMake(0,(CGRectGetHeight(self.frame)-120)/2, CGRectGetWidth(self.frame),120)];
    contentView.layer.cornerRadius=kmargin/2;
    contentView.backgroundColor=WhiteColor;
    contentView.backgroundColor=MAIN_BACK_COLOR;
    [self addSubview:contentView];
    
    UILabel *titleLabel=[contentView getLabelWithText:NSLocalizedString(@"Select the Gender", nil) font:Font_Number(16) textColor:Main_Color textAlignment:NSTextAlignmentCenter lineBreakMode:NSLineBreakByTruncatingTail numberOfLines:1];//@"选择性别"
    [contentView addSubview:titleLabel];
    titleLabel.frame=CGRectMake((APPW-100)/2,kmargin,100,30);
    
    
    _sexTableView=[[UITableView alloc] initWithFrame:CGRectMake(0,CGRectGetHeight(titleLabel.frame)+kmargin,CGRectGetWidth(contentView.frame),CGRectGetHeight(contentView.frame)) style:UITableViewStylePlain];
    _sexTableView.dataSource=self;
    _sexTableView.delegate=self;
    _sexTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    _sexTableView.backgroundColor=MAIN_BACK_COLOR;
    _sexTableView.backgroundColor=WhiteColor;
    _sexTableView.showsHorizontalScrollIndicator=NO;
    _sexTableView.showsVerticalScrollIndicator=NO;
    [_sexTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableViewCellIdentifier];
    [contentView addSubview:_sexTableView];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.sexArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableViewCellIdentifier];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    cell.contentView.layer.borderColor=Main_Color.CGColor;
    cell.textLabel.text=[NSString stringWithFormat:@"%@",self.sexArr[indexPath.row]];
    cell.textLabel.textAlignment=NSTextAlignmentCenter;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 45;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    // 获取_sexTableView 当前选中的cell
    UITableViewCell *cell=[_sexTableView cellForRowAtIndexPath:indexPath];

    if ([self.delegate respondsToSelector:@selector(selectSexWithIndex:sex:)])
    {
         [self.delegate selectSexWithIndex:indexPath.row sex:cell.textLabel.text];
        
         cell.textLabel.textColor=Main_Color;
        //NSLog(@"00223332--%@",cell.textLabel.text);
        
    }
}

@end
